commonlibsse_ng\re\i/
IMemoryHeap.rs1use core::ffi::{c_char, c_void};
2
3use crate::re::offsets_rtti::RTTI_IMemoryHeap;
4use crate::re::offsets_vtable::VTABLE_IMemoryHeap;
5use crate::rel::id::VariantID;
6
7bitflags::bitflags! {
8 #[repr(transparent)]
9 #[derive(Debug, Default,Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
10 pub struct MEM_CONTEXT: u32 {}
11}
12
13#[repr(C)]
15#[derive(Debug, Clone, PartialEq)]
16pub struct HeapStats {
17 pub heapName: *const c_char, pub memHeapSize: usize, pub memHeapCommitted: usize, pub memAllocatedToBlocks: usize, pub numBlocks: i32, pub numFreeBlocks: i32, pub memFreeInBlocks: usize, pub memUsedInBlocks: usize, pub smallestFreeBlock: usize, pub largestFreeBlock: usize, pub heapOverhead: usize, pub freeListOverhead: usize, pub blockOverhead: usize, pub totalFree: usize, }
32
33const _: () = {
34 assert!(std::mem::size_of::<HeapStats>() == 0x68);
35};
36
37#[repr(C)]
39pub struct IMemoryHeap {
40 pub vtable: *const IMemoryHeapVtbl,
41}
42
43#[repr(C)]
44pub struct IMemoryHeapVtbl {
45 pub CxxDrop: unsafe extern "C" fn(this: *mut IMemoryHeap), pub Size: unsafe extern "C" fn(this: *const IMemoryHeap, mem: *const c_void) -> usize, pub GetMemoryStats: unsafe extern "C" fn(this: *mut IMemoryHeap, stats: *mut HeapStats), pub ContainsBlockImpl:
50 unsafe extern "C" fn(this: *const IMemoryHeap, block: *const c_void) -> bool, pub AllocateAlignImpl:
52 unsafe extern "C" fn(this: *mut IMemoryHeap, size: usize, alignment: u32) -> *mut c_void, pub DeallocateAlignImpl: unsafe extern "C" fn(this: *mut IMemoryHeap, block: *mut *mut c_void), pub GetName: unsafe extern "C" fn(this: *const IMemoryHeap) -> *const c_char, pub Allocate:
58 unsafe extern "C" fn(this: *mut IMemoryHeap, size: usize, alignment: u32) -> *mut c_void, pub Deallocate: unsafe extern "C" fn(this: *mut IMemoryHeap, mem: *mut c_void, alignment: u32), pub PointerInHeap:
61 unsafe extern "C" fn(this: *const IMemoryHeap, pointer: *const c_void) -> bool, pub TotalSize: unsafe extern "C" fn(this: *const IMemoryHeap, pointer: *const c_void) -> usize, pub GetHeapStats:
64 unsafe extern "C" fn(this: *mut IMemoryHeap, stats: *mut HeapStats, full_block_info: bool), pub ShouldTrySmallBlockPools:
66 unsafe extern "C" fn(this: *const IMemoryHeap, size: usize, context: MEM_CONTEXT) -> bool, pub GetPageSize: unsafe extern "C" fn(this: *const IMemoryHeap) -> u32, }
69
70impl IMemoryHeap {
71 pub const RTTI: VariantID = RTTI_IMemoryHeap;
73
74 pub const VTABLE: [VariantID; 1] = VTABLE_IMemoryHeap;
76
77 pub unsafe fn get_name(&self) -> *const c_char {
81 unsafe { ((*self.vtable).GetName)(self) }
82 }
83
84 pub unsafe fn allocate(&mut self, size: usize, alignment: u32) -> *mut c_void {
88 unsafe { ((*self.vtable).Allocate)(self, size, alignment) }
89 }
90
91 pub unsafe fn deallocate(&mut self, mem: *mut c_void, alignment: u32) {
95 unsafe { ((*self.vtable).Deallocate)(self, mem, alignment) };
96 }
97
98 pub unsafe fn pointer_in_heap(&self, pointer: *const c_void) -> bool {
102 unsafe { ((*self.vtable).PointerInHeap)(self, pointer) }
103 }
104
105 pub unsafe fn total_size(&self, pointer: *const c_void) -> usize {
109 unsafe { ((*self.vtable).TotalSize)(self, pointer) }
110 }
111
112 pub unsafe fn get_heap_stats(&mut self, stats: *mut HeapStats, full_block_info: bool) {
116 unsafe { ((*self.vtable).GetHeapStats)(self, stats, full_block_info) };
117 }
118
119 pub unsafe fn should_try_small_block_pools(&self, size: usize, context: MEM_CONTEXT) -> bool {
123 unsafe { ((*self.vtable).ShouldTrySmallBlockPools)(self, size, context) }
124 }
125
126 pub unsafe fn get_page_size(&self) -> u32 {
130 unsafe { ((*self.vtable).GetPageSize)(self) }
131 }
132}